package com.harassment.interception.ui.activities.main;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.TextView;

import com.harassment.interception.R;
import com.harassment.interception.data.databases.entities.InterceptedSms;
import com.harassment.interception.util.DateFormat;

public class ShowSmsActivity extends AppCompatActivity {
    public static final String SMS_NUMBER = "smsNumber";
    public static final String SMS_CONTENT = "smsContent";
    public static final String SMS_DATE_TIME = "smsDateTime";
    private static final String TAG = "ShowSmsActivity";
    private TextView mSmsContent;
    private TextView mSmsDateTime;
    private Toolbar mToolbar;

    public static void startShowSmsAction(Context context, InterceptedSms interceptedSms) {
        Intent intent = new Intent(context, ShowSmsActivity.class);
        intent.putExtra(SMS_NUMBER, interceptedSms.getNumber());
        intent.putExtra(SMS_CONTENT, interceptedSms.getContent());
        intent.putExtra(SMS_DATE_TIME, DateFormat.format(interceptedSms.getDateTime()));
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_sms);
        initActionBar();
        mSmsContent = findViewById(R.id.sms_content);
        mSmsDateTime = findViewById(R.id.date_time);
        String content = getIntent().getStringExtra(SMS_CONTENT);
        String dateTime = getIntent().getStringExtra(SMS_DATE_TIME);
        if (content != null) {
            mSmsContent.setText(content);
        }
        if (dateTime != null) {
            mSmsDateTime.setText(dateTime);
        }

    }

    private void initActionBar() {
        if (mToolbar == null) {
            mToolbar = findViewById(R.id.base_action_bar);
        }
        super.setSupportActionBar(mToolbar);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        Intent intent = getIntent();
        actionBar.setTitle(intent.getStringExtra(SMS_NUMBER));
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        boolean result = false;
        switch (item.getItemId()) {
            case android.R.id.home:
                result = true;
                finish();
                break;
        }
        return result;
    }
}
